#include<bits/stdc++.h>
#define int long long
#define For(i,a,b) for(int i=a;i<=b;++i)
#define Rof(i,a,b) for(int i=a;i>=b;--i)
#define rep(i,a) for(int i=1;i<=a;++i)
#define print(x) printf("%lld\n",(int)x)
#define prn(x) printf("%lld ",(int)x)
using namespace std;
const int N=2e6+5,Mod=998244353;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){f=(ch=='-'?-f:f);ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*f;
}
bool SSS;
int n,r;
int gg[N],tot,vis[N];
int tt[N];
void dfs(int x){
	if(x==n+1){
		int sum=0;
		For(i,2,n){
			sum+=gg[i-1];
			if(sum<=gg[i]) return;
		}
		int p=0;
		//~ For(i,1,n) cout<<gg[i]<<" ";
		//~ puts("");
		For(i,1,n){
			p=p*8+(gg[i]-1);
		}
		//~ cout<<p<<" ";
		tt[++tot]=p;
		return;
	}
	For(i,1,n){
		if(vis[i]) continue;
		gg[x]=i;
		vis[i]=1;
		dfs(x+1);
		vis[i]=0;gg[x]=0;
	}
}
int cnt,bks;
__int128 p=0,fac[N];
vector<int>q;
void dfs1(int x,int qzh){
	if(bks) return ;
	if(qzh>n){
		++cnt;
		if(fac[n-x+1]==0||p+fac[n-x+1]>=r){
			For(i,1,x-1) q.push_back(gg[i]);
			bks=1;
			return;
		}
		else{
			p+=fac[n-x+1];
		}
		return;
	}
	For(i,1,(qzh==0?n:qzh-1)){
		if(vis[i]) continue;
		gg[x]=i;
		vis[i]=1;
		dfs1(x+1,qzh+i);
		if(bks) return;
		vis[i]=0;gg[x]=0;
	}
}
int pp[N];
bool viis[N];
int zz[N],ttt;
bool vs[N];
int ans[N];
bool TTT;
signed main(){
	freopen("permutation.in","r",stdin);
	freopen("permutation.out","w",stdout);
	n=read(),r=read();
	fac[0]=1;
	For(i,1,100){
		fac[i]=fac[i-1]*i;
		if(fac[i]>1000000000000000000) break;
	}
	if(n<=8){
		dfs(1);
		sort(tt+1,tt+tot+1);
		int x=tt[r];
		For(i,1,n){
			pp[i]=x%8+1;
			x/=8;
		}
		Rof(i,n,1) printf("%lld ",pp[i]);
		return 0;
	}
	if(r==1){
		printf("3 1 2 ");
		For(i,4,n) {
			printf("%lld ",i);
		}
		puts("");
		return 0;
	}
	if(r==2){
		printf("3 1 2 ");
		For(i,4,n-2) {
			printf("%lld ",i);
		}printf("%lld %lld ",n,n-1);
		puts("");
		return 0;
	}
	dfs1(1,0);
	int as=0;set<int>s;
	For(i,1,n) s.insert(i);
	for(auto v:q)viis[v]=1,ans[++as]=v,s.erase(v);
	int t=r-p;
	int ttt=n-q.size();
	
	For(i,1,ttt){
		int pp=ttt-i;
		if(fac[pp]==0){
			int p=*s.begin();
			ans[++as]=p;
			s.erase(p);
			continue;
		}
		int p=*s.begin();
		For(j,1,ttt){
			//~ cout<<t<<" ";
			if(t>fac[pp]){
				t-=fac[pp];
				p=*s.lower_bound(p+1);
			}
			else{
				s.erase(p);
				ans[++as]=p;
				break;
			}
		}//puts("");
	}
	For(i,1,n) printf("%lld ",ans[i]);
	//~ cout<<fixed<<setprecision(10)<<1.0*clock()/CLOCKS_PER_SEC<<endl;
	return 0;
}
//
